<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style type="text/css">
    body {
      margin: 0px;
      text-align: center;
    }

    #reg {
      width: 370px;
      border: 1px solid blue;
      line-height: 40px;
      margin: 0 auto;
      padding-left: 100px;
      padding-top: 15px;
      padding-bottom: 15px;
      text-align: left;
      font-size: 14px;
    }

    /* 以下使用的是属性选择器，具体来说是属性值选择器 */
    input[type="submit"] {
      padding: 10px 15px;
      margin: 5px;
      background: #4CAF50;
      color: white;
      border: none;
      border-radius: 4px;
    }
  </style>
  <form method="POST" action="" style="margin: 20px;">
    <div id="reg">
      数值1:<div><input type="number" name="num1" value="<?php echo $_POST['num1'] ? $_POST['num1'] : 0 ?>" placeholder="输入第一个数字" step="any"></div>
      数值2:<div><input type="number" name="num2" value="<?php echo $_POST['num2'] ? $_POST['num2'] : 0 ?>" placeholder="输入第二个数字" step="any"></div>
      <div>
        <input type="submit" name="operation" value="+">
        <input type="submit" name="operation" value="-">
        <input type="submit" name="operation" value="*">
        <input type="submit" name="operation" value="/">
      </div>
      <div>
        结果：<input type="text" value="<?php
                                      $num1 = isset($_POST['num1']) ? $_POST['num1'] : 0;
                                      $num2 = isset($_POST['num2']) ? $_POST['num2'] : 0;
                                      $operation = isset($_POST['operation']) ? $_POST['operation'] : 0;
                                      if (is_numeric($num1) && is_numeric($num2)) {
                                        switch ($operation) {
                                          case '+':
                                            echo $num1 + $num2;
                                            break;
                                          case '-':
                                            echo $num1 - $num2;
                                            break;
                                          case '*':
                                            echo $num1 * $num2;
                                            break;
                                          case '/':
                                            echo $num1 / $num2;
                                            break;
                                        }
                                      }
                                      ?>">
      </div>
    </div>
  </form>
</head>

<body>
</body>

</html>